<style>
* {font-family:Arial, Helvetica, sans-serif; font-size:14px}
#fade { /*--Transparent background layer--*/
        display: none; /*--hidden by default--*/
        background: #727272;
        position: fixed; left: 0; top: 0;
        width: 100%; height: 100%;
        opacity: .50;
        z-index: 9999;
}
.popup_block{
        display: none; /*--hidden by default--*/
        background:url(images/bgn.png);
       
		border-radius: 8px;
        float: left;
        font-size: 1.2em;
        position: fixed;
        top: 50%; left: 50%;
        z-index: 99999;
		width:463px;
		height:264px;
		
        /*--CSS3 Box Shadows--*/
        /*--CSS3 Rounded Corners--*/
}
.btn_close {
	background:url(images/close.png);
        float: right;
        margin: -10px -10px 0 0;
		width:30px;
		height:30px;
}
/*--Making IE6 Understand Fixed Positioning--*/
*html #fade {
        position: absolute;
}
*html .popup_block {
        position: absolute;
}

.btnupbg {
	/*background: none repeat scroll 0 0 #79AA38;*/
	background:url(images/btn.png) no-repeat;
    border-color: #C4C0B9;
    border-radius: 5px 5px 5px 5px;
    border-width: 0;
    color: white;
    cursor: pointer;
    font-weight: bold;
    height: 28px;
    margin: 6px 0 0 20px;
    padding: 0 5px;
    width: 65px;}
.btnupbg:hover {background:#309DCF}
.btnupload {background: -moz-linear-gradient(center top , #63B6DB, #309DCF) repeat;}
.text{ height:24px;}
</style>
<style type="text/css">
p {margin:0; padding:0}
img {border:none}
.mtable {border:1px solid #c2c2c2; border-collapse:collapse; background:white}
.mtable thead td {background:#eee; color:#027acc; font-weight:bold}
.mtable tr td {border-bottom:1px solid #c2c2c2; border-right:1px solid #c2c2c2; padding:6px}

.cpanel {background:url(images/bg.png) no-repeat; width:142px; height:28px;}
.cpanel a {padding-left:10px; padding-right:10px}
.cpanel a img {padding-top:2px}
</style>
<link rel="stylesheet" type="text/css" href="js/jsDatePick_ltr.min.css" />
<script type="text/javascript" src="js/jsDatePick.min.1.3.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript">

function loaddate(){
	
	new JsDatePick({
	
	useMode:2,
	
	target:"date_stop",
	dateFormat:"%Y-%m-%d"
	
	});

};

</script>
<script type="text/javascript">
<!--

function addLicense(){
	var email=document.getElementById("email_chooser").value;
	var license=document.getElementById("type_license").value;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
		  if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    	document.getElementById("giayphep1").innerHTML=xmlhttp.responseText;
		  }
	  }
	xmlhttp.open("GET","ajax/license.php?action=addLicense&email="+email+"&license="+license,true);
	xmlhttp.send();
}
function delLicense(id){
	hoi= confirm("<?=$hoi?>");
	if (hoi==true) {
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}else{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function(){
			  if (xmlhttp.readyState==4 && xmlhttp.status==200){
			    	document.getElementById("giayphep1").innerHTML=xmlhttp.responseText;
			  }
		  }
		xmlhttp.open("GET","ajax/license.php?action=delLicense&id_license="+id,true);
		xmlhttp.send();
	}

}
function stopLicense(id){
	hoi= confirm("<?=$hoi?>");
	if (hoi==true) {
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}else{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function(){
			  if (xmlhttp.readyState==4 && xmlhttp.status==200){
			    	document.getElementById("giayphep2").innerHTML=xmlhttp.responseText;
			  }
		  }
		xmlhttp.open("GET","ajax/license1.php?action=stopLicense&id_license="+id,true);
		xmlhttp.send();
	}

}
function startLicense(id,time){
	hoi= confirm("<?=$hoi?>");
	if (hoi==true) {
		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}else{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function(){
			  if (xmlhttp.readyState==4 && xmlhttp.status==200){
			    	document.getElementById("giayphep2").innerHTML=xmlhttp.responseText;
			  }
		  }
		xmlhttp.open("GET","ajax/license1.php?action=startLicense&id_license="+id+"&time="+time,true);
		xmlhttp.send();
	}
}
function editLicense(){
	var id_license=document.getElementById("id_license").value;
	var date_stop=document.getElementById("date_stop").value;
	var date_stop1=document.getElementById("date_stop1").value;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
		  if (xmlhttp.readyState==4 && xmlhttp.status==200){
		    	document.getElementById("giayphep1").innerHTML=xmlhttp.responseText;
		  }
	  }
	xmlhttp.open("GET","ajax/license.php?action=editLicense&id_license="+id_license+"&date_stop="+date_stop+"&date_stop1="+date_stop1,true);
	xmlhttp.send();


}
function calladdLicense(email,ele){
	popuploadbel(ele);
	document.getElementById("email_chooser").value=email;
}
function calleditLicense(id_license,date_stop,ele){
	
	popuploadbel(ele);
	document.getElementById("id_license").value=id_license;
	document.getElementById("date_stop1").value=date_stop;
	document.getElementById("date_stop").value=date_stop;
	loaddate();
}
//-->
</script>

<?php 
	if(!isset($_SESSION['role'])){
		if(!isset($_COOKIE['role'])){
			$_SESSION['action']='login';
			header( 'Location: index.php' );
		}else{
			$_SESSION['tkemail']=$_COOKIE["tkemail"];
		    $_SESSION['tkemailrestore']=$_COOKIE["tkemailrestore"];
		    $_SESSION['role']=$_COOKIE["role"];
			
			$role=$_SESSION['role'];
			$tkemail=$_SESSION['tkemail'];
		}
	}else{
		$role=$_SESSION['role'];
		$tkemail=$_SESSION['tkemail'];
	}

?>

	<div id="popup_name" class="popup_block" style="height:100px">
			
           	<table style="width:100%;border:1;padding-top: 10px;padding-bottom: 10px;">
            		<tr>
            			<td><span style="color: #027acc;padding-left:5px;"><?=$namelicense?> : </span></td>
            			<td>
            				<?php 	include 'connection/connection.php';
							$query=mysql_query("SELECT t.id_type_license,t.time FROM type_license t;");
							?>
            					<input type="hidden" id="email_chooser" value="asdasd"/>
								<select name="type_license" id="type_license" style="width: 95%;padding-right: 5px;">
								<?php 
								while ($row=mysql_fetch_array($query)){
									if($row['time']!=0){
									?>
									<option value="<?=$row['id_type_license']?>"><?=$row['time']?> <?=$month?></option>
								<?php	 }		}?>
								</select>
							<?php mysql_close($connection);?>
            			</td>
            		</tr>
            		<tr>
            			<td></td>
            			<td style="align:center;padding-top: 10px;">
				   			<input type="button" onclick="addLicense()" style="font-family:Arial, Helvetica, sans-serif; font-size:12px;" class="btnupbg iclose" value="<?=$them?>" name="changePass" />
				            <input type="submit" class="btnupbg iclose"  style="font-family:Arial, Helvetica, sans-serif; font-size:12px;" value="<?=$cancel?>"  name="cancel" />
            			</td>
            		</tr>
            	</table>
    </div>
    <div id="popup_name1" class="popup_block" style="height: 100px">
            <table style="width:100%;border:1;padding-top: 10px;padding-bottom: 10px;">
            	<tr>
            		<td><span style="color: #027acc;padding-left:5px;"><?=$date_stop?> :</span></td>
            		<td>
            			<input type="hidden" id="id_license" value="asdasd"/>
						<input id="date_stop1" value="asdasd" type="hidden"/>
						<input id="date_stop" value="asdasd"  style="width: 90%;padding-right: 5px;"/>
            		</td>
            	</tr>
            	<tr>
            		<td></td>
            		<td align="left">(yyyy-mm-dd)</td>
            	</tr>
            	<tr>
            		<td></td>
            		<td style="align:center;padding-bottom: 10px;">
            			<input type="button" onclick="editLicense()" style="font-family:Arial, Helvetica, sans-serif; font-size:12px;margin: 6px 0 0 11px;" class="btnupbg iclose" value="<?=$edit?>" name="changePass" />
            			<input type="submit" class="btnupbg iclose"  style="font-family:Arial, Helvetica, sans-serif; font-size:12px;margin: 6px 0 0 11px;" value="<?=$cancel?>"  name="cancel" />
            		</td>
            	</tr>
            </table>
    </div>
    <div class="maincon1">
        <div class="hbox">
           <h2><?=$login?> </h2>
            <p><?=$login1?></p>
            <div class="seldown">
            	<?php if($lang=="EN"){?>
                	<a href="#" onclick="changePage('hoso')" ><img src="images/hoso_en_2.png" title="<?=$hoso?>" /></a>
                	<a href="#" ><img src="images/giayphep_en_1.png" title="<?=$namelicense?>" /></a>
                <?php }?>
                <?php if($lang=="KR"){?>
                	<a href="#" onclick="changePage('hoso')" ><img src="images/hoso_kr_2.png" title="<?=$hoso?>" /></a>
                	<a href="#" ><img src="images/giayphep_kr_1.png" title="<?=$namelicense?>" /></a>
                <?php }?>
                <?php if($lang=="VN"){?>
                	<a href="#" onclick="changePage('hoso')" ><img src="images/hoso_vn_2.png" title="<?=$hoso?>" /></a>
                	<a href="#" ><img src="images/giayphep_vn_1.png" title="<?=$namelicense?>" /></a>
                <?php }?>
            </div>
        </div>
    </div>
    	<div class="maind">   
    		<?php if($role==0){?>
    		<div id="giayphep2" style="padding-left: 90px;"> 
    		<?php 
				include 'connection/connection.php';
    			$query=mysql_query("SELECT l.id_license,l.email,l.status,t.time,l.date_start,l.date_stop 
									FROM license l,type_license t 
									WHERE l.email='$tkemail' AND l.id_type_license=t.id_type_license;");
    			
				 $list_license=array();
				 $email_temp="";
				 $co=0;
				 while ($row=mysql_fetch_array($query)){
				 	if($row['status']==2){
				 		$co=2;
				 	}
				 	$list_license[$row['email']][]=array($row['time'],$row['status'],$row['date_start'],$row['date_stop'],$row['id_license']);
				 }
				 mysql_close($connection);
			?>
	       <table width="800" cellpadding="0" cellspacing="0" class="mtable">
	    	<thead>
	        	<tr>
	                <td align="center"><?=$address_email?></td>
	                <td align="center"><?=$type_license?></td>
	                <td align="center"><?=$namestatus?></td>
	                <td align="center"><?=$date_start?></td>
	                <td align="center"><?=$date_stop?></td>
	                <td align="center"></td>
	                
	            </tr>
	        </thead>
	       <?php 
	        foreach ($list_license as $email => $license){
	        	
	        	for($i=0;$i<count($license);$i++){	
	        	?>
	        	<?php
	        			if($license[$i][0]==0){
	        				$time=$free;
	        			}else{
	        				$time=$license[$i][0]." ".$month;
	        			}
	        			
	        			
	        			if($license[$i][1]==1){
	        				$color='white';
	        				$status=$status1;
	        			}
	        			if($license[$i][1]==""){
	        				$color='white';
	        				$status="";
	        				$month="";
	        				$time="";
	        			}
	        			if($license[$i][1]==2){
	        				$color='#B2DAF7';
	        				$status=$status2;
	        			}
	        			if($license[$i][1]==3){
	        				$color='#F1DFDC';
	        				$status=$status3;
	        			}
	        	if($i==0){
	        			
	        		
	        		?>
		        <tr>
		        		<td rowspan="<?=count($license)?>"><?=$email?></td>
		        	
		            		<td  style="background-color: <?=$color?>;" align="center"><?=$time?></td>
			        		<td  style="background-color: <?=$color?>;" align="center"><?=$status?></td>
		            		<td  style="background-color: <?=$color?>;" align="center"><?=$license[$i][2]?></td>
		            		<td  style="background-color: <?=$color?>;" align="center"><?=$license[$i][3]?></td>
		            		<td style="background-color: <?=$color?>;" align="center">
					            <?php if($co==0)  if($license[$i][1]==1){?><a onclick="startLicense('<?=$license[$i][4]?>','<?=$license[$i][0]?>')" ><img src="images/edit.png" title="<?php echo $start;?>" /></a><?php }?>
		            			<?php if($co==2)  if($license[$i][1]==2){?><a onclick="stopLicense('<?=$license[$i][4]?>')"><img src="images/xoa.png" title="<?=$del1?>" /></a><?php }?>
		            		</td>
		        </tr>
		        <?php }else{?>
	        	<tr>
		        		<td  style="background-color: <?=$color?>;" align="center"><?=$time?></td>
		        		<td  style="background-color: <?=$color?>;" align="center"><?=$status?></td>
	            		<td  style="background-color: <?=$color?>;" align="center"><?=$license[$i][2]?></td>
	            		<td  style="background-color: <?=$color?>;" align="center"><?=$license[$i][3]?></td>
	            		<td  style="background-color: <?=$color?>;" align="center">
	            			<?php if($co==0)  if($license[$i][1]==1){?><a  onclick="startLicense('<?=$license[$i][4]?>','<?=$license[$i][0]?>')"><img src="images/edit.png" title="<?php echo $start;?>" /></a><?php }?>
		            		<?php if($co==2) if($license[$i][1]==2){?><a onclick="stopLicense('<?=$license[$i][4]?>')"><img src="images/xoa.png" title="<?=$del1?>" /></a><?php }?>
	            		</td>
	        	</tr>
	      	<?php } }
	        	}?>
	    </table>
		</div>
		<?php }?>
    		<?php if($role==1){?>
    		<div id="giayphep1" style="padding-left: 90px;"> 
    		<?php 
				include 'connection/connection.php';
				$query=mysql_query("SELECT e.email,t.time,e.status,e.date_start,e.date_stop,e.id_license 
									FROM (SELECT u.email,u.role,l.id_type_license,l.status,l.date_start,l.date_stop,l.id_license
												FROM user_info u 
															LEFT JOIN license l ON u.email=l.email) e 
												LEFT JOIN type_license t ON e.id_type_license=t.id_type_license
									WHERE e.role=0;");
				 $list_license=array();
				 $email_temp="";
				 while ($row=mysql_fetch_array($query)){
				 	$list_license[$row['email']][]=array($row['time'],$row['status'],$row['date_start'],$row['date_stop'],$row['id_license']);
				 }
				 mysql_close($connection);
			?>
	       <table width="800" cellpadding="0" cellspacing="0" class="mtable">
	    	<thead>
	        	<tr>
	                <td align="center"><?=$address_email?></td>
	                <td align="center"><?=$type_license?></td>
	                <td align="center"><?=$namestatus?></td>
	                <td align="center"><?=$date_start?></td>
	                <td align="center"><?=$date_stop?></td>
	                <td align="center"></td>
	                <td align="center"></td>
	            </tr>
	        </thead>
	        <?php 
	        foreach ($list_license as $email => $license){
	        	
	        	for($i=0;$i<count($license);$i++){	
	        	?>
	        	<?php
	        			if($license[$i][0]==0){
	        				$time=$free;
	        			}else{
	        				$time=$license[$i][0]." ".$month;
	        			}
	        			
	        			
	        			if($license[$i][1]==1){
	        				$color='white';
	        				$status=$status1;
	        			}
	        			if($license[$i][1]==""){
	        				$color='white';
	        				$status="";
	        				$time="";
	        			}
	        			if($license[$i][1]==2){
	        				$color='#B2DAF7';
	        				$status=$status2;
	        			}
	        			if($license[$i][1]==3){
	        				$color='#F1DFDC';
	        				$status=$status3;
	        			}
	        	if($i==0){
	        			
	        		
	        		?>
		        <tr>
		        		<td rowspan="<?=count($license)?>"><?=$email?></td>
		        	
		            		<td  style="background-color: <?=$color?>;" align="center"><?=$time?></td>
			        		<td  style="background-color: <?=$color?>;" align="center"><?=$status?></td>
		            		<td  style="background-color: <?=$color?>;" align="center"><?=$license[$i][2]?></td>
		            		<td  style="background-color: <?=$color?>;" align="center"><?=$license[$i][3]?></td>
		            		<td style="background-color: <?=$color?>;" align="center">
		            			<?php if($license[$i][1]==2 && $license[$i][0]!=0){?><a href="#?w=260" onclick="calleditLicense('<?=$license[$i][4]?>','<?=$license[$i][3]?>',this)" rel="popup_name1" class="poplight"><img src="images/edit.png" title="<?php echo $edit;?>" /></a><?php }?>
		            			<?php if($license[$i][1]==3){?><a onclick="delLicense('<?=$license[$i][4]?>')"><img src="images/xoa.png"  title="<?php echo $del2;?>" /></a><?php }?>
		            		</td>
			            <td rowspan="<?=count($license)?>">
			            	<a href="#?w=300" onclick="calladdLicense('<?=$email?>',this)" rel="popup_name" class="poplight" style="padding-left:10px"><img src="images/them.png" title="<?php echo $them;?>" /></a>
			         	</td>
		        </tr>
		        <?php }else{?>
	        	<tr>
		        		<td  style="background-color: <?=$color?>;" align="center"><?=$time?></td>
		        		<td  style="background-color: <?=$color?>;" align="center"><?=$status?></td>
	            		<td  style="background-color: <?=$color?>;" align="center"><?=$license[$i][2]?></td>
	            		<td  style="background-color: <?=$color?>;" align="center"><?=$license[$i][3]?></td>
	            		<td style="background-color: <?=$color?>;" align="center" >
		            		<?php  if($license[$i][1]==2 && $license[$i][0]!=0){?><a href="#?w=260" onclick="calleditLicense('<?=$license[$i][4]?>','<?=$license[$i][3]?>',this)" rel="popup_name1" class="poplight"><img src="images/edit.png" title="<?php echo $edit;?>" /></a><?php }?>
		            		<?php  if($license[$i][1]==3){?><a onclick="delLicense('<?=$license[$i][4]?>')"><img src="images/xoa.png" title="<?php echo $del2;?>" /></a><?php }?>
	            		</td>
	        	</tr>
	      	<?php } }
	        	}?>
	    </table>
		</div>
		<?php }?>
	    </div>
 
  
    
